package groupOne.app.DWD.db;

import groupOne.app.BaseAppSql;
import groupOne.common.Constant;
import groupOne.util.SQLUtil;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

public class Dwd_01_TestTestExam_Xiang extends BaseAppSql {
    public static void main(String[] args) {
        new Dwd_01_TestTestExam_Xiang().init(
                6001,
                2,
                "Dwd_01_Test_Test_Exam_Xiang"
        );
    }
    @Override
    protected void handle(StreamExecutionEnvironment env, StreamTableEnvironment tEnv) {
        readOdsDb(tEnv,"Dwd_01_Test_Test_Exam_Xiang");
        Table result = tEnv.sqlQuery("select " +
                "data['id'] id,  " +
                "data['paper_id'] paper_id,  " +
                "data['user_id'] user_id,  " +
                "data['score'] score,  " +
                "data['duration_sec'] duration_sec,  " +
                "data['create_time'] create_time,  " + //考试时间
                "data['submit_time'] submit_time,  " + //提交时间
                "data['update_time'] update_time,  " + //更新时间（没用）
                "data['deleted'] deleted," +
                "ts " +
                "from ods_db " +
                "where `database` = 'edu' " +
                "and `table` = 'test_exam' " +
                "and `type` = 'insert' ");
//        result.execute().print();
        tEnv.executeSql("create table dwd_test_test_exam(" +
                "id string,  " +
                "paper_id string,  " +
                "user_id string,  " +
                "score string,  " +
                "duration_sec string,  " +
                "create_time string,  " +
                "submit_time string,  " +
                "update_time string,  " +
                "deleted string, " +
                "ts bigint " +
                ")"+ SQLUtil.getKafkaSink(Constant.TOPIC_DWD_TEST_TEST_EXAM));
        result.executeInsert("dwd_test_test_exam");
    }
}
